﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaggerApp.MSTagRefService;
using System.IO;
using System.Data.SqlClient;

namespace TaggerApp
{
    public class MakeTags
    {
        //Renders a Microsoft Tag
        public string RenderTag(string productName, string productGUID)
        {
            try
            {
                MIBPContractClient OMIBPClient = new MIBPContractClient();
                UserCredential oCredential = new UserCredential();

                oCredential.AccessToken = ConfigurationManager.AppSettings["MSTagAPIKey"];
                byte[] oBarcode = OMIBPClient.GetBarcode(oCredential, "Main", productName, ImageTypes.jpeg, 1, DecorationType.HCCBRP_DECORATION_NONE, false);

                //render the oBarcode byte array into an image.
                string tagImage = Convert.ToBase64String(oBarcode, 0, oBarcode.Length);
                return "data:image/png;base64," + tagImage;

            }
            catch
            {
                throw;
            }
        }

        //Renders a QR Code
        public string RenderQR(string productName, string productGUID)
        {
            try
            {
                MIBPContractClient OMIBPClient = new MIBPContractClient();
                UserCredential oCredential = new UserCredential();

                oCredential.AccessToken = ConfigurationManager.AppSettings["MSTagAPIKey"];
                byte[] oBarcode = OMIBPClient.GetQRCode(
                                    oCredential, "Main", productName,
                                    ImageTypes.jpeg, 1, false);

                //render the oBarcode byte array into an image.
                string tagImage = Convert.ToBase64String(oBarcode, 0, oBarcode.Length);
                return "data:image/png;base64," + tagImage;
            }
            catch
            {
                throw;
            }
        }
    }
}